# def solve(board):
#     def dfs(x,y):
#         if not 0<= x <n or not 0<=y<n or board[x][y] != 0:
#             return
#         board[x][y] = 'A'
#         dfs(x+1,y)
#         dfs(x-1,y)
#         dfs(x,y+1)
#         dfs(x,y-1)
#
#     if not board or not board[0]:
#         return
#     n = len(board)
#     for i in range(n-1):
#         dfs(i,0)
#         dfs(i,n-1)
#
#     for i in range(n-1):
#         dfs(0,i)
#         dfs(n-1,i)
#
#     for i in range(n):
#         for j in range(n):
#             print(i,j)
#             if board[i][j] == 'A':
#                 board[i][j] = 0
#             else:
#                 board[i][j] = 2
#
#
# n = int(input())
# board = []
# for _ in range(n):
#     ls = list(map(int,input().split()))
#     board.append(ls)
#
# solve(board)
#
# print(board)

def solve(board):
    def dfs(board,row,col):
        n = len(board)
        if row<0 or row == n or col<0 or col == n or board[row][col] != 0:
            return
        board[row][col] = 3
        dfs(board,row+1,col)
        dfs(board,row,col+1)
        dfs(board,row-1,col)
        dfs(board,row,col-1)

    n = len(board)
    for i in range(n):
        if board[i][0] == 0:
            dfs(board,i,0)
        if board[i][n-1] == 0:
            dfs(board,i,n-1)
    for i in range(n):
        if board[0][i] == 0:
            dfs(board,0,i)
        if board[n-1][i] == 0:
            dfs(board,n-1,i)

    for i in range(n):
        for j in range(n):
            if board[i][j] == 0:
                board[i][j] = 2
            if board[i][j] == 3:
                board[i][j] = 0
            print(board[i][j],end=' ')
        print()

n = int(input())
board = []
for _ in range(n):
    ls = list(map(int,input().split()))
    board.append(ls)
solve(board)






# 6
# 0 1 0 0 1 0
# 1 0 1 1 0 1
# 0 1 0 0 1 0
# 0 1 0 0 1 0
# 1 0 1 1 0 1
# 0 1 0 0 1 0





